home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / casestdy / ch17_dav / clock.dcr / 00021_Main Puzzle Script.ls < prev    next >
Encoding:
Text File  |  1996-11-12  |  3.8 KB  |  124 lines

  1. global cBoundSprite, cGridSprite, cGridL, cGridT, cGridSpace, cHalfGridSpace, cGridHList, cGridVList, gTileTrackList, gTileLocList, cShadowSprite, cFloatSprite, gTileObjList, cTileOffset, cRightEdge, cBottomEdge, cHandCursor, cFingerCursor, cFistCursor, gLastRollover
  2.  
  3. on initPuzzle
  4.   setPuzzleConstants()
  5.   setPuzzleGlobals()
  6.   puppetSprite(cShadowSprite, 1)
  7.   puppetSprite(cFloatSprite, 1)
  8.   set the randomSeed to the ticks
  9.   puppetTempo(120)
  10. end
  11.  
  12. on setPuzzleConstants
  13.   set cBoundSprite to 1
  14.   set cGridSprite to 2
  15.   set cTileOffset to 11
  16.   set cGridL to the left of sprite cGridSprite
  17.   set cGridT to the top of sprite cGridSprite
  18.   set cGridSpace to 50
  19.   set cHalfGridSpace to cGridSpace / 2
  20.   set cShadowSprite to 47
  21.   set cFloatSprite to 48
  22.   set cRightEdge to the stageRight - the stageLeft
  23.   set cBottomEdge to the stageBottom - the stageTop
  24.   set cHandCursor to [the number of member "Hand", the number of member "Hand Mask"]
  25.   set cFingerCursor to [the number of member "Finger", the number of member "Finger Mask"]
  26.   set cFistCursor to [the number of member "Fist", the number of member "Fist Mask"]
  27. end
  28.  
  29. on setPuzzleGlobals
  30.   set cGridHList to [:]
  31.   set cGridVList to [:]
  32.   set firstPointH to cGridL + cHalfGridSpace
  33.   set firstPointV to cGridT + cHalfGridSpace
  34.   addProp(cGridHList, firstPointH, firstPointH)
  35.   addProp(cGridVList, firstPointV, firstPointV)
  36.   repeat with x = 1 to 3
  37.     set HLoc to firstPointH + (x * cGridSpace)
  38.     addProp(cGridHList, HLoc, HLoc)
  39.     set VLoc to firstPointV + (x * cGridSpace)
  40.     addProp(cGridVList, VLoc, VLoc)
  41.   end repeat
  42.   sort(cGridHList)
  43.   sort(cGridVList)
  44.   set gTileTrackList to ["11": EMPTY, "12": EMPTY, "13": EMPTY, "14": EMPTY, "21": EMPTY, "22": EMPTY, "23": EMPTY, "24": EMPTY, "31": EMPTY, "32": EMPTY, "33": EMPTY, "34": EMPTY, "41": EMPTY, "42": EMPTY, "43": EMPTY, "44": EMPTY]
  45.   set gTileLocList to []
  46.   repeat with i = 1 to 16
  47.     append(gTileLocList, the loc of sprite (i + cTileOffset))
  48.   end repeat
  49.   set shuffleList to ListShuffler(16)
  50.   set gTileObjList to []
  51.   repeat with i = 1 to 16
  52.     set whichSprite to i + cTileOffset
  53.     puppetSprite(whichSprite, 1)
  54.     set whichMem to the name of cast the castNum of sprite whichSprite
  55.     add(gTileObjList, new(script "Tile Parent Script", whichSprite, whichMem))
  56.     set whichNum to getAt(shuffleList, i)
  57.     set the loc of sprite whichSprite to getAt(gTileLocList, whichNum)
  58.   end repeat
  59. end
  60.  
  61. on moveTile
  62.   set whichSprite to the clickOn
  63.   set whichTileObj to whichSprite - cTileOffset
  64.   dragTile(getAt(gTileObjList, whichTileObj))
  65.   checkForWin()
  66. end
  67.  
  68. on checkForWin
  69.   set checkNum to 0
  70.   repeat with x = 1 to count(gTileTrackList)
  71.     set checkProp to getPropAt(gTileTrackList, x)
  72.     set checkValue to getAt(gTileTrackList, x)
  73.     if checkProp = checkValue then
  74.       set checkNum to checkNum + 1
  75.       next repeat
  76.     end if
  77.     exit
  78.   end repeat
  79.   if checkNum = 16 then
  80.     pupsOff()
  81.     cursor(-1)
  82.     go("Clock")
  83.   end if
  84. end
  85.  
  86. on ListShuffler howMany
  87.   set shuffleList to []
  88.   repeat with x = 1 to howMany
  89.     addAt(shuffleList, x, x)
  90.   end repeat
  91.   repeat with x = 1 to howMany
  92.     set randVar to random(howMany)
  93.     set TempVar to getAt(shuffleList, x)
  94.     set a to getAt(shuffleList, randVar)
  95.     setAt(shuffleList, x, a)
  96.     setAt(shuffleList, randVar, TempVar)
  97.   end repeat
  98.   return shuffleList
  99. end
  100.  
  101. on pupsOff
  102.   repeat with x = 1 to 48
  103.     puppetSprite(x, 0)
  104.   end repeat
  105. end
  106.  
  107. on checkRoll
  108.   repeat with spriteCounter = 10 to 27
  109.     set gLastRollover to 46
  110.     cursor(-1)
  111.     if rollOver(spriteCounter) and (spriteCounter <> gLastRollover) then
  112.       set gLastRollover to spriteCounter
  113.       if (spriteCounter = 10) or (spriteCounter = 11) then
  114.         cursor(cFingerCursor)
  115.       else
  116.         cursor(cHandCursor)
  117.       end if
  118.       repeat while rollOver(spriteCounter) and the mouseUp
  119.       end repeat
  120.       exit repeat
  121.     end if
  122.   end repeat
  123. end
  124.